#!/usr/bin/python
# -*- coding:utf-8 -*-
#
# 生成器
mested = [[1,2], [3,4],[5]]
def flatten(nested):
	for sublist in nested:
		for element in sublist:
			yield element

for num in flatten(mested):
	print num

# print list(flatten(mested))

# 递归
def newFlatten(nested):
	try:
		for sublist in nested:
			for element in newFlatten(sublist):
				print 'element is ',element
				yield element
	except TypeError:
		yield nested

mested_1 = [[[1],2], [[3],4],[5]]
print list(newFlatten(mested_1))
